<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>欢迎访问</title>
    <style>
        body { margin: 0; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
        
        .loading-container {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background: #f8f9fa;
        }
        
        .loader {
            border: 5px solid rgba(52, 152, 219, 0.3);
            border-radius: 50%;
            border-top: 5px solid #3498db;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin-bottom: 20px;
        }
        
        @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
        
        .loading-text { color: #333; font-size: 18px; }
        
        .error-container {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background: #f8f9fa;
        }
        
        .forbidden-text {
            color: #333;
            font-size: 24px;
            font-weight: bold;
        }
        
        #contentFrame {
            display: none;
            width: 100%;
            height: 100vh;
            border: none;
        }
    </style>
    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; frame-src *; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
</head>
<body>
    <div id="loadingContainer" class="loading-container">
        <div class="loader"></div>
        <div class="loading-text">网页加载中，请稍后...</div>
    </div>
    
    <iframe id="contentFrame"></iframe>
    <div id="errorContainer" class="error-container" style="display: none;"></div>

    <script>
        // 白名单：支持两种格式
        // 1. 域名（如https://www.example.com → 允许该域名下所有页面）
        // 2. 带路径（如https://www.example.com/blog → 仅允许该路径下的页面）
        const WHITELIST = [
            "http://fufeiaa.9i0.fun",         
            "https://www.baidu.com",           
            "https://github.com/username/repo" 
        ];

        const loading = document.getElementById('loadingContainer');
        const iframe = document.getElementById('contentFrame');
        const error = document.getElementById('errorContainer');

        const getQuery = (param) => {
            try { return new URLSearchParams(location.search).get(param); }
            catch (e) { return null; }
        };

        const isInWhitelist = (url) => {
            try {
                const parsedUrl = new URL(url);
                return WHITELIST.some(white => {
                    return parsedUrl.origin === white || url.startsWith(white);
                });
            } catch (e) {
                return false;
            }
        };

        const showError = (msg, isForbidden = false) => {
            loading.style.display = 'none';
            if (isForbidden) {
                error.innerHTML = `<div class="forbidden-text">禁止访问</div>`;
            } else {
                error.innerHTML = `<h1>加载失败</h1><p>${msg}</p><p>请检查链接或稍后再试。</p>`;
            }
            error.style.display = 'flex';
        };

        (() => {
            const base64Url = getQuery('u');
            if (!base64Url) return showError('缺少参数 u');

            const decodedUrl = atob(base64Url);
            if (!/^https?:\/\//.test(decodedUrl)) {
                return showError('无效的URL（需以http/https开头）');
            }

            if (!isInWhitelist(decodedUrl)) {
                return showError('', true);
            }

            iframe.src = decodedUrl;
            iframe.onload = () => {
                loading.style.display = 'none';
                iframe.style.display = 'block';
            };
            setTimeout(() => {
                if (loading.style.display !== 'none') {
                    showError('加载超时（超过60秒）');
                }
            }, 60000);
        })();
    </script>
</body>
</html>
    